package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.RevenueDAO;
import com.zerosky.crm.po.Revenue;
import com.zerosky.crm.service.RevenueService;
import com.zerosky.crm.util.PageInfo;

@Service(value = "revenueService")
public class RevenueServiceImpl implements RevenueService {
	@Autowired
	private RevenueDAO RevenueDao;

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Revenue> getRevenueAllList(Map map) {
		return RevenueDao.getRevenueAllList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Revenue> getRevenuePageInfoList(Map map) {
		int begin = (((int) map.get("page") - 1) * (int) map.get("limit"));
		int pageSize = (int) map.get("limit");
		PageInfo<Revenue> page = new PageInfo<Revenue>();
		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<Revenue> list = RevenueDao.getRevenueAllList(map);
		page.setList(list);

		Integer count = RevenueDao.countRevenue(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Revenue getRevenueById(String RevenueId) {
		return RevenueDao.getRevenueById(RevenueId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void addRevenue(Revenue Revenue) {
		RevenueDao.addRevenue(Revenue);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void updateRevenue(Revenue Revenue) {
		RevenueDao.updateRevenue(Revenue);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteRevenueById(String RevenueId) {
		RevenueDao.deleteRevenueById(RevenueId);
	}
}
